package com.haier.spark.project.dao.impl

import com.haier.spark.project.dao.ISessionDetailDao
import com.haier.spark.project.domain.SessionDetail
import com.haier.spark.project.jdbc.JDBCHelper

import scala.collection.mutable.ListBuffer

class SessionDetailDaoImpl extends ISessionDetailDao{
  def insert(sessionDetail: SessionDetail): Unit = {
    val sql:String = "insert into session_detail values(?,?,?,?,?,?,?,?,?,?,?,?)"
    val params: Array[Any] = Array(sessionDetail.taskId,
      sessionDetail.userId,
      sessionDetail.sessionId,
      sessionDetail.pageId,
      sessionDetail.actionTime,
      sessionDetail.searchKeyword,
      sessionDetail.clickCategoryId,
      sessionDetail.clickProductId,
      sessionDetail.orderCategoryIds,
      sessionDetail.orderProductIds,
      sessionDetail.payCategoryIds,
      sessionDetail.payProductIds)
    JDBCHelper.executeUpdate(sql, params)
  }

  override def insertBatch(sessionDetails: ListBuffer[SessionDetail]): Unit = {
    val sql:String = "insert into session_detail values(?,?,?,?,?,?,?,?,?,?,?,?)"
    val params: ListBuffer[Array[Any]] = new ListBuffer[Array[Any]]
    sessionDetails.foreach(item => {
      params.append(Array(item.taskId,
        item.userId,
        item.sessionId,
        item.pageId,
        item.actionTime,
        item.searchKeyword,
        item.clickCategoryId,
        item.clickProductId,
        item.orderCategoryIds,
        item.orderProductIds,
        item.payCategoryIds,
        item.payProductIds))
    })
    JDBCHelper.executeBatch(sql, params.toList)
  }
}
